package cn.fanyamin.util.io;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * The Class ConsoleUtils.
 *
 * @author walter
 */
public final class ConsoleUtils {
        
        /**
         * Instantiates a new console utils.
         */
        private ConsoleUtils() {
            
        }
        /** The input stream. */
        private static InputStreamReader inputStream = new InputStreamReader(System.in);
        
        /** The reader. */
        private static BufferedReader reader = new BufferedReader(inputStream);

        /**
         * Gets the number from console.
         *
         * @return the number from console
         */
        public static int getNumberFromConsole() {
            int number = 0;
            try {
                number = Integer.parseInt(reader.readLine());
            } catch (Exception e) {
                System.out.println("Enter a valid integer!!");
            }
            return number;
        }

        /**
         * Gets the string from console.
         *
         * @return the string from console
         */
        public static String getStringFromConsole() {
            String strInput="";
            try {
                strInput = reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return strInput;
        }

}
